<template src="../template/master.html">
</template>

<script type="text/javascript">
import getQueryString from '../../es/stringUtil';

export default {
  name: 'master',
  data() {
    return {
      cdn: `${window.location.protocol}//${window.location.host}/3.0/`,
      menuStatus: true,
      menuList: [],
      depatementName: '未登录',
      userName: '未登录',
      messageNum: 0,
      messageStatus: false,
      popNotice: null,
      activeMenu: '',
      openedMenu: [],
    };
  },
  mounted() {
    if (getQueryString('urlCode')) {
      this.menuStatus = false;
    }
    this.qryUserAuthorMenu();
    this.searchMainPageUserInfo();
  },
  computed: {
  },
  watch: {
    /* eslint-disable */
    '$route' (to) {
      this.activeMenu = to.fullPath;
      for (const menu of this.activeMenu) {
        if (menu.children && menu.children.length) {
          for (sub of menu.children) {
            if(subchild.children && subchild.children.length) {
              for(subchild of subchild.children) {
                if (subchild.url === this.activeMenu) {
                  this.openedMenu = [menu.name];
                  break;
                }
              }
            }
            if (sub.url === this.activeMenu) {
              this.openedMenu = [menu.name];
              break;
            }
          }
        }
      }
      setTimeout(() => {
        const el = this.$refs.menu.$el;
        const parent = el.parentElement;
        const opened = el.querySelector('.el-submenu.is-active.is-opened');
        const active = el.querySelector('.el-menu-item.is-active');
        const scrollTop = parent.scrollTop;
        const menuHeight = parent.clientHeight;
        let outTop = 0, titleHeight= 0, innerTop = 0, activeHeight = 0;
        if (opened) {
          outTop = opened.offsetTop;
          titleHeight = opened.querySelector('.el-submenu__title').clientHeight;
        }
        if (active) {
          innerTop = active.offsetTop;
          activeHeight = active.clientHeight;
        }
        const diffTop = outTop + titleHeight + innerTop - scrollTop - menuHeight;
        if (diffTop > 0) {
          this.$refs.menuWrap.scrollTop = activeHeight + diffTop;
        }
      }, 400);
    },
    /* eslint-enable */
  },
  methods: {
    async logout() {
      const parmas = {
        channelcode: 'SSO',
      };
      await this.$http.post('loginoutAction', parmas).then(
        () => {
          this.$message({
            message: '退出登录成功',
            type: 'success',
          });
        },
        () => {},
      );
      setTimeout(() => {
        window.opener = null;
        window.open('about:blank', '_top').close();
      }, 0);
    },
    qryUserAuthorMenu() {
      this.$http.post('qryUserAuthorMenu.ajax', {}).then(
        (res) => {
          res = res.body;
          this.menuList = res.rspData;
        },
        () => {},
      );
    },
     // 个人信息接口
    searchMainPageUserInfo() {
      this.$http.post('searchMainPageUserInfo.ajax').then(
        (res) => {
          res = res.body;
          this.depatementName = res.rspData.depatementName;
          this.userName = res.rspData.name;
        },
        () => {},
      );
    },
    gotoMessage() {
      this.messageStatus = false;
      this.$router.push('/myMessage');
    },
  },
};
</script>

<style lang="scss" src='../css/master.scss'></style>
<style lang="scss" src='../../assets/css/style.scss'></style>
<style lang="scss" src='../../assets/css/theme.scss'></style>

